home *** CD-ROM | disk | FTP | other *** search
/ isnet Internet / Isnet Internet CD.iso / prog / hiz / 09 / 09.exe / adynware.exe / perl / lib / File / stat.pm < prev   
Encoding:
Perl POD Document  |  1999-12-28  |  2.8 KB  |  113 lines

  1. package File::stat;
  2. use strict;
  3.  
  4. BEGIN { 
  5.     use Exporter   ();
  6.     use vars       qw(@EXPORT @EXPORT_OK %EXPORT_TAGS);
  7.     @EXPORT      = qw(stat lstat);
  8.     @EXPORT_OK   = qw( $st_dev       $st_ino    $st_mode 
  9.                $st_nlink   $st_uid    $st_gid 
  10.                $st_rdev    $st_size 
  11.                $st_atime   $st_mtime  $st_ctime 
  12.                $st_blksize $st_blocks
  13.             );
  14.     %EXPORT_TAGS = ( FIELDS => [ @EXPORT_OK, @EXPORT ] );
  15. }
  16. use vars      @EXPORT_OK;
  17.  
  18. sub import { goto &Exporter::import }
  19.  
  20. use Class::Struct qw(struct);
  21. struct 'File::stat' => [
  22.      map { $_ => '$' } qw{
  23.      dev ino mode nlink uid gid rdev size
  24.      atime mtime ctime blksize blocks
  25.      }
  26. ];
  27.  
  28. sub populate (@) {
  29.     return unless @_;
  30.     my $stob = new();
  31.     @$stob = (
  32.     $st_dev, $st_ino, $st_mode, $st_nlink, $st_uid, $st_gid, $st_rdev,
  33.         $st_size, $st_atime, $st_mtime, $st_ctime, $st_blksize, $st_blocks ) 
  34.         = @_;
  35.     return $stob;
  36.  
  37. sub lstat ($)  { populate(CORE::lstat(shift)) }
  38.  
  39. sub stat ($) {
  40.     my $arg = shift;
  41.     my $st = populate(CORE::stat $arg);
  42.     return $st if $st;
  43.     no strict 'refs';
  44.     require Symbol;
  45.     return populate(CORE::stat \*{Symbol::qualify($arg)});
  46. }
  47.  
  48. 1;
  49. __END__
  50.  
  51. =head1 NAME
  52.  
  53. File::stat - by-name interface to Perl's built-in stat() functions
  54.  
  55. =head1 SYNOPSIS
  56.  
  57.  use File::stat;
  58.  $st = stat($file) or die "No $file: $!";
  59.  if ( ($st->mode & 0111) && $st->nlink > 1) ) {
  60.      print "$file is executable with lotsa links\n";
  61.  } 
  62.  
  63.  use File::stat qw(:FIELDS);
  64.  stat($file) or die "No $file: $!";
  65.  if ( ($st_mode & 0111) && $st_nlink > 1) ) {
  66.      print "$file is executable with lotsa links\n";
  67.  } 
  68.  
  69. =head1 DESCRIPTION
  70.  
  71. This module's default exports override the core stat() 
  72. and lstat() functions, replacing them with versions that return 
  73. "File::stat" objects.  This object has methods that
  74. return the similarly named structure field name from the
  75. stat(2) function; namely,
  76. dev,
  77. ino,
  78. mode,
  79. nlink,
  80. uid,
  81. gid,
  82. rdev,
  83. size,
  84. atime,
  85. mtime,
  86. ctime,
  87. blksize,
  88. and
  89. blocks.  
  90.  
  91. You may also import all the structure fields directly into your namespace
  92. as regular variables using the :FIELDS import tag.  (Note that this still
  93. overrides your stat() and lstat() functions.)  Access these fields as
  94. variables named with a preceding C<st_> in front their method names.
  95. Thus, C<$stat_obj-E<gt>dev()> corresponds to $st_dev if you import
  96. the fields.
  97.  
  98. To access this functionality without the core overrides,
  99. pass the C<use> an empty import list, and then access
  100. function functions with their full qualified names.
  101. On the other hand, the built-ins are still available
  102. via the C<CORE::> pseudo-package.
  103.  
  104. =head1 NOTE
  105.  
  106. While this class is currently implemented using the Class::Struct
  107. module to build a struct-like class, you shouldn't rely upon this.
  108.  
  109. =head1 AUTHOR
  110.  
  111. Tom Christiansen
  112.